#!/bin/bash

set -x
VERSION="1.22"
wget https://raw.githubusercontent.com/istio/istio/release-${VERSION}/samples/addons/jaeger.yaml
sed -i 's/ClusterIP/NodePort/g' jaeger.yaml
kubectl apply -f jaeger.yaml

## back 1.20 file
#cat << EOF | kubectl apply -f -
#apiVersion: apps/v1
#kind: Deployment
#metadata:
#  name: jaeger
#  namespace: istio-system
#  labels:
#    app: jaeger
#spec:
#  selector:
#    matchLabels:
#      app: jaeger
#  template:
#    metadata:
#      labels:
#        app: jaeger
#        sidecar.istio.io/inject: "false"
#      annotations:
#        prometheus.io/scrape: "true"
#        prometheus.io/port: "14269"
#    spec:
#      containers:
#        - name: jaeger
#          image: "docker.io/jaegertracing/all-in-one:1.46"
#          env:
#            - name: BADGER_EPHEMERAL
#              value: "false"
#            - name: SPAN_STORAGE_TYPE
#              value: "badger"
#            - name: BADGER_DIRECTORY_VALUE
#              value: "/badger/data"
#            - name: BADGER_DIRECTORY_KEY
#              value: "/badger/key"
#            - name: COLLECTOR_ZIPKIN_HOST_PORT
#              value: ":9411"
#            - name: MEMORY_MAX_TRACES
#              value: "50000"
#            - name: QUERY_BASE_PATH
#              value: /jaeger
#          livenessProbe:
#            httpGet:
#              path: /
#              port: 14269
#          readinessProbe:
#            httpGet:
#              path: /
#              port: 14269
#          volumeMounts:
#            - name: data
#              mountPath: /badger
#          resources:
#            requests:
#              cpu: 10m
#      volumes:
#        - name: data
#          emptyDir: {}
#---
#apiVersion: v1
#kind: Service
#metadata:
#  name: tracing
#  namespace: istio-system
#  labels:
#    app: jaeger
#spec:
#  type: NodePort
#  ports:
#    - name: http-query
#      port: 80
#      protocol: TCP
#      targetPort: 16686
#    # Note: Change port name if you add '--query.grpc.tls.enabled=true'
#    - name: grpc-query
#      port: 16685
#      protocol: TCP
#      targetPort: 16685
#  selector:
#    app: jaeger
#---
## Jaeger implements the Zipkin API. To support swapping out the tracing backend, we use a Service named Zipkin.
#apiVersion: v1
#kind: Service
#metadata:
#  labels:
#    name: zipkin
#  name: zipkin
#  namespace: istio-system
#spec:
#  ports:
#    - port: 9411
#      targetPort: 9411
#      name: http-query
#  selector:
#    app: jaeger
#---
#apiVersion: v1
#kind: Service
#metadata:
#  name: jaeger-collector
#  namespace: istio-system
#  labels:
#    app: jaeger
#spec:
#  type: NodePort
#  ports:
#  - name: jaeger-collector-http
#    port: 14268
#    targetPort: 14268
#    protocol: TCP
#  - name: jaeger-collector-grpc
#    port: 14250
#    targetPort: 14250
#    protocol: TCP
#  - port: 9411
#    targetPort: 9411
#    name: http-zipkin
#  - port: 4317
#    name: grpc-otel
#  - port: 4318
#    name: http-otel
#  selector:
#    app: jaeger
#EOF

set +x
